//
//  MSSearchButton.m
//  MSJD
//
//  Created by 箭军刘 on 2018/11/3.
//  Copyright © 2018 xiangbo. All rights reserved.
//

#import "MSSearchButton.h"

@interface MSSearchButton()

@end

@implementation MSSearchButton

+ (instancetype)initSearchButtonWithTitle:(NSString *)title {
    MSSearchButton *searchButton = [[MSSearchButton alloc] initWithFrame:CGRectZero title:title];
    return searchButton;
}

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title {
    if (self = [super initWithFrame:frame]) {
        
        [self setTitle:title forState:UIControlStateNormal];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [self setTitleColor:[UIColor colorWithHexString:@"#444444"] forState:UIControlStateNormal];
        [self setBackgroundColor:[UIColor colorWithHexString:@"#F2F2F2"]];
        
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}

#pragma mark - Public Method

+ (CGFloat)caculateButtonHeightWihtTitle:(NSString *)title {
    CGRect rect = [title boundingRectWithSize:CGSizeMake(300, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil];
    return CGRectGetWidth(rect) + 32.0;
}

#pragma mark - Setters

- (void)setSelected:(BOOL)selected {
    [super setSelected:selected];
    [self setBackgroundColor:selected?MSThemeColor:[UIColor colorWithHexString:@"#F2F2F2"]];
}


@end
